package com.hailintang.demo.geekbang.course05;

//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//import java.util.concurrent.TimeUnit;
//
//@RestController
//@RequestMapping("clientreadtimeout")
//@Slf4j
//public class ClientReadTimeoutController {
//    private String getResponse(String url, int connectTimeout, int readTimeout) throws IOException {
//        return Request.Get("http://localhost:45678/clientreadtimeout" + url)
//                .connectTimeout(connectTimeout)
//                .socketTimeout(readTimeout)
//                .execute()
//                .returnContent()
//                .asString();
//    }
//
//    @GetMapping("client")
//    public String client() throws IOException {
//        log.info("client1 called");
//        //服务端5s超时，客户端读取超时2秒
//        return getResponse("/server?timeout=5000", 1000, 2000);
//    }
//
//    @GetMapping("server")
//    public void server(@RequestParam("timeout") int timeout) throws InterruptedException {
//        log.info("server called");
//        TimeUnit.MILLISECONDS.sleep(timeout);
//        log.info("Done");
//    }
//}